package com.zs.admin.controller.wisdbook;

import com.zs.admin.aop.Log;
import com.zs.admin.service.wisdbook.IWisdbookUserService;
import com.zs.admin.validate.wisdbook.WisdbookUserCreateValidate;
import com.zs.admin.validate.wisdbook.WisdbookUserSearchValidate;
import com.zs.admin.validate.wisdbook.WisdbookUserUpdateValidate;
import com.zs.admin.validate.commons.IdValidate;
import com.zs.admin.validate.commons.PageValidate;
import com.zs.admin.vo.wisdbook.WisdbookUserDetailVo;
import com.zs.admin.vo.wisdbook.WisdbookUserListedVo;
import com.zs.admin.vo.system.SystemAuthAdminListedVo;
import com.zs.common.core.AjaxResult;
import com.zs.common.core.PageResult;
import com.zs.common.validator.annotation.IDMust;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.util.Assert;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("api/wisdbook/user")
@Api(tags = "标记任务管理")
public class WisdbookUserController {

    @Resource
    IWisdbookUserService iWisdbookUserService;


    @Log(title = "标记编辑选择列表")
    @GetMapping("/select")
    @ApiOperation(value="标记编辑选择列表")
    public AjaxResult<PageResult<SystemAuthAdminListedVo>> selectUsers(@Validated PageValidate pageValidate, @Validated IdValidate idValidate) {
        PageResult<SystemAuthAdminListedVo> list = iWisdbookUserService.selectUsers(pageValidate, idValidate);
        return AjaxResult.success(list);
    }


    @GetMapping("/getMarkerUserWithBookId")
    @ApiOperation(value="标记任务列表")
    public AjaxResult<WisdbookUserDetailVo> getMarkerUserWithBookId(@Validated @IDMust()  Integer bookId) {
        WisdbookUserSearchValidate wisdbookUserSearchValidate = new WisdbookUserSearchValidate();
        wisdbookUserSearchValidate.setBookId(bookId);
        WisdbookUserDetailVo vo = iWisdbookUserService.get(wisdbookUserSearchValidate);
        return AjaxResult.success(vo);
    }


    @Log(title = "标记任务新增")
    @PostMapping("/add")
    @ApiOperation(value="标记任务新增")
    public AjaxResult<Object> add(@Validated @RequestBody WisdbookUserCreateValidate createValidate) {

        WisdbookUserSearchValidate wisdbookUserSearchValidate = new WisdbookUserSearchValidate();
        wisdbookUserSearchValidate.setBookId(createValidate.getBookId());
        WisdbookUserDetailVo vo = iWisdbookUserService.get(wisdbookUserSearchValidate);
        Assert.isNull(vo, "数据存在!");
        iWisdbookUserService.add(createValidate);
        return AjaxResult.success();
    }


    @Log(title = "标记任务编辑")
    @PostMapping("/edit")
    @ApiOperation(value="标记任务编辑")
    public AjaxResult<Object> edit(@Validated @RequestBody WisdbookUserUpdateValidate updateValidate) {
        iWisdbookUserService.edit(updateValidate);
        return AjaxResult.success();
    }

    @GetMapping("/listByUser")
    @ApiOperation(value="标记任务列表")
    public AjaxResult<PageResult<WisdbookUserListedVo>> listByUser(@Validated PageValidate pageValidate, @Validated WisdbookUserSearchValidate searchValidate) {
        PageResult<WisdbookUserListedVo> list = iWisdbookUserService.listByUser(pageValidate, searchValidate);
        return AjaxResult.success(list);
    }

    @GetMapping("/list")
    @ApiOperation(value="标记任务列表")
    public AjaxResult<PageResult<WisdbookUserListedVo>> list(@Validated PageValidate pageValidate,
                                                     @Validated WisdbookUserSearchValidate searchValidate) {
        PageResult<WisdbookUserListedVo> list = iWisdbookUserService.list(pageValidate, searchValidate);
        return AjaxResult.success(list);
    }

    @GetMapping("/detail")
    @ApiOperation(value="标记任务详情")
    public AjaxResult<WisdbookUserDetailVo> detail(@Validated @IDMust() @RequestParam("id") Integer id) {
        WisdbookUserDetailVo detail = iWisdbookUserService.detail(id);
        return AjaxResult.success(detail);
    }



    @Log(title = "标记任务删除")
    @PostMapping("/del")
    @ApiOperation(value="标记任务删除")
    public AjaxResult<Object> del(@Validated @RequestBody IdValidate idValidate) {
        iWisdbookUserService.del(idValidate.getId());
        return AjaxResult.success();
    }

}
